<?php
class CategoryAction extends CommonAction {
    public function index(){
		$this->setSeo(array(), 'category');
		
		$websitesObject = D('Websites');
		
		if(true || !($websitesCountCate = F('websites_count_cate'))){
			//获得主要部分的数据
			if(!($websitesCate = F('websites_cate'))){
				$websitesCate = D('WebsitesCate')->getCateTree();
				F('websites_cate', $websitesCate);
			}
			
			
			$websitesCountCate = array();
			foreach($websitesCate as $key=>$val){
				$websitesCountCate[$key] = $val;
				$websitesCountCate[$key]['count'] = $websitesObject->where(array('cate_id'=>$val['id'], 'status'=>1))->count();
				
				if($val['tree']){
					foreach($val['tree'] as $k=>$v){
						$websitesCountCate[$key]['tree'][$k] = $v;
						$websitesCountCate[$key]['tree'][$k]['count'] = $websitesObject->where(array('cate_id'=>$v['id'], 'status'=>1))->count();
						$websitesCountCate[$key]['count'] += $websitesCountCate[$key]['tree'][$k]['count'];
					}	
				}
			}
			
			F('websites_count_cate', $websitesCountCate);
		}
		
		
		$this->assign('websitesCate', $websitesCountCate);
		$this->display();
    }
}